package com.buba.service.impl;

import com.buba.dao.MenuMapper;
import com.buba.pojo.Menu;
import com.buba.service.MenuService;
import com.buba.vo.MenuVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class MenuServiceImpl implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    public List<Menu> findMenuList() {
        /**
         * todo 查询所有菜单列表
         * @return
         */
        return menuMapper.listMenu();
    }
    /**
     * todo 根据角色ID查询该角色拥有的菜单ID集合
     * @param roleId
     * @return
     */
    public List<Integer> findMenuIdListByRoleId(int roleId) {

        return menuMapper.findMenuIdListByRoleId(roleId);
    }

    /**
     * todo 根据菜单编号查询菜单信息
     * @param currentRoleMenuIds
     * @return
     */
    public List<Menu> findMenuByMenuId(List<Integer> currentRoleMenuIds) {
        return menuMapper.findMenuByMenuId(currentRoleMenuIds);
    }

    /**
     * todo 查询菜单列表
     * @param menuVO
     * @return
     */
    public List<Menu> findMenuListByPage(MenuVO menuVO) {
        return menuMapper.findMenuListByPage(menuVO);
    }

    /**
     * todo 添加菜单
     * @param menu
     * @return
     */
    public int addMenu(Menu menu) {
        //如果没有选择父级菜单，默认设置父级菜单为0
        if (menu.getPid() == null) {
            menu.setPid(0);
        }
        //设置打开方式，没有作用
        menu.setTarget("_self");
        return menuMapper.addMenu(menu);
    }

    /**
     * todo 修改菜单
     * @param menu
     * @return
     */
    public int updateMenu(Menu menu) {
        return menuMapper.updateMenu(menu);
    }

    /**
     *  todo 根据菜单ID查询该菜单是否有子菜单
     * @param id
     * @return
     */
    public int getMenuCountByMenuId(Integer id) {
        return menuMapper.getMenuCountByMenuId(id);
    }

    /**
     * todo 删除菜单
     * @param id
     * @return
     */
    public int deleteById(int id) {
        return menuMapper.deleteById(id);
    }

    /**
     * todo 根据当前登录员工的角色查询菜单列表
     * @param employeeId
     * @return
     */
    public List<Menu> findMenuListByEmployeeId(Integer employeeId) {
        return menuMapper.findMenuListByEmployeeId(employeeId);
    }

}
